package com.jie.deletefile.Listview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.jie.deletefile.Listview.adapter.ErshaAdapter;
import com.jie.deletefile.R;

import java.util.ArrayList;
import java.util.List;

public class ErshaActivity extends AppCompatActivity {

    private ListView ersha_lv;
    private ErshaAdapter adapter;
    private List<String> datas;
    private List<Boolean> ishow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ersha);
        initView();
    }

    private void initView() {
        ersha_lv = (ListView) findViewById(R.id.ersha_lv);
        datas = new ArrayList<>();
        ishow = new ArrayList<>();
        for (int i=0;i<10;i++) {
            datas.add("我是傻瓜" + i + "号");
            ishow.add(false);
        }

        adapter = new ErshaAdapter(this, datas);
        ersha_lv.setAdapter(adapter);
        ersha_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.e("TAG", "onItemClick: ===============" );
                if (!ishow.get(position)) {
                    Log.e("TAG", "onItemClick: false" );
                    ErshaAdapter.ViewHold hold = new ErshaAdapter.ViewHold(view);
                    Log.e("TAG", "onItemClick: ssss"+(hold.getListView()==null ));
                    hold.getListView().setVisibility(View.VISIBLE);
                    ishow.remove(position);
//                    parent.addView(hold.getListView());
                    ishow.add(position, true);
                } else {
                    Log.e("TAG", "onItemClick: ture" );
                    ErshaAdapter.ViewHold hold = new ErshaAdapter.ViewHold(view);
                    hold.getListView().setVisibility(View.GONE);
                    ishow.remove(position);
                    ishow.add(position, false);
                }
            }
        });
    }

}
